/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.openbravo.bean.erp;

import e.odbo.data.bean.I_AutoGeneratorStringKey;
import e.odbo.data.bean.I_ModifiedLogBean;
import java.util.Date;


/**
 *
 * @author Administrator
 */
public class OrderType implements I_ModifiedLogBean<String>,I_AutoGeneratorStringKey{

     static final long serialVersionUID=-289978955053645676L;

     public String id;//单据类型唯一索引
     public int inOutType;//库存出入类型
     public int inOutType1;//库存出入类型1
     public String subjectRefId;//会计科目引用ID
     public String name;//单据显示名称
     public int priceType;//价格类型
     public boolean changePrice;//是否修改目标价格
     public String reverseName;//对应返转单据名
     public int consultType;//参照类型
     public int fundType;//资金类型
     public String attributesetid;//属性引用

     public int orderLineType;//单据行类型

     public boolean cashAddAble;//直接现金

     public  String categoryid; //单据类型分类

     public String stateMachine;//状态机

     public  boolean productConsult;//是否引用产品（否)
     
     public boolean checkRule;//是否校验规则

     //库存出入类型
     public static int STORE_In=1;
     public static int STORE_Out=-1;
     public static int STORE_NoChange=0;
     public static int STORE_First_In_Second_Out=2;
     public static int STORE_First_Out_Second_In=3;
     public static int STORE_BalanceIn=4;
     public static int STORE_BalanceOut=5;

     //价格----------------------------->
     public static int PRICETYPE_BuyPrice=0;
     public static int PRICETYPE_SellPrice=1;
     public static int PRICETYPE_CustomerPrice=2;
     public static int PRICETYPE_CustomerCategoryPrice=3;
     public static int PRICETYPE_WholesalePrice=4;
     public static int PRICETYPE_WholesaleCustomerCategoryPrice=5;
     
     //是否修改目标价格
     public static boolean PRICE_NoChange=false;
     public static boolean PRICE_Change=true;

     //数量------------------------->
     public static int CONSULTTYPE_Null=0;
     public static int CONSULTTYPE_Order=1;//单据
     public static int CONSULTTYPE_TimeSliceStore=2;//时间片库存
     public static int CONSULTTYPE_RealStore=3;//实时库存

     //资金类型
     public static int FUNDTYPE_NoChange=0;
     public static int FUNDTYPE_In=1;
     public static int FUNDTYPE_Out=2;

     //单据行类型
     public static int ORDERLINETYPE_SupportAll=0;
     public static int ORDERLINETYPE_NotSupportAll=1;
     public static int ORDERLINETYPE_SupportProduct=2;
     public static int ORDERLINETYPE_SupportUniqueProduct=3;
     public static int ORDERLINETYPE_SupportUniqueProductAdded=4;
     public static int ORDERLINETYPE_SupportService=5;
     public static int ORDERLINETYPE_SupportProductAndService=6;
     public static int ORDERLINETYPE_SupportUniqueProductAndService=7;
     public static int ORDERLINETYPE_SupportUniqueProductAddAndService=8;

     private Date lastModified;

     private String processName;

     private boolean serviceCheck;//服务是否应有效校验
     private String selectedOrderRuleProcess;
     
     public static int PRICETYPE_noConsult=-1;
     public int consultPriceType;//参照类型

    public OrderType() {
        this(null);
    }

    public OrderType(String inId) {
        id=inId;
        inOutType=STORE_In;
        priceType=PRICETYPE_SellPrice;
        changePrice=PRICE_Change;
        consultType=CONSULTTYPE_Null;
        fundType=FUNDTYPE_NoChange;
        subjectRefId=null;
        name=null;
        reverseName=null;
        attributesetid=null;
        orderLineType=ORDERLINETYPE_SupportAll;
        cashAddAble=true;
        categoryid=null;
        inOutType1=STORE_NoChange;
        stateMachine=null;
        productConsult=false;
        serviceCheck=true;
        consultPriceType=PRICETYPE_noConsult;
        checkRule=false;
    }

    public OrderType(String id, int inOutType, int inOutType1, String subjectRefId, String name, int priceType, boolean changePrice, String reverseName, int consultType, int fundType, String attributesetid, int orderLineType, boolean cashAddAble, String categoryid) {
        this.id = id;
        this.inOutType = inOutType;
        this.inOutType1 = inOutType1;
        this.subjectRefId = subjectRefId;
        this.name = name;
        this.priceType = priceType;
        this.changePrice = changePrice;
        this.reverseName = reverseName;
        this.consultType = consultType;
        this.fundType = fundType;
        this.attributesetid = attributesetid;
        this.orderLineType = orderLineType;
        this.cashAddAble = cashAddAble;
        this.categoryid = categoryid;
        productConsult=false;
        serviceCheck=true;
        checkRule=false;
        consultPriceType=PRICETYPE_noConsult;
    }

    public void reverse(){
       if(inOutType==STORE_In)
                inOutType=STORE_Out;
       else if(inOutType==STORE_Out)
                inOutType=STORE_In;
       if(inOutType==STORE_BalanceIn)
            inOutType=STORE_BalanceOut;

       if(inOutType1==STORE_In)
                inOutType1=STORE_Out;
       else if(inOutType1==STORE_Out)
                inOutType1=STORE_In;
       if(inOutType1==STORE_BalanceIn)
            inOutType1=STORE_BalanceOut;

       if(fundType==OrderType.FUNDTYPE_Out)
           fundType=OrderType.FUNDTYPE_In;
       else if(fundType==OrderType.FUNDTYPE_In)
           fundType=OrderType.FUNDTYPE_Out;
    }


    public boolean isChangePrice() {
        return changePrice;
    }

    public void setChangePrice(boolean changePrice) {
        this.changePrice = changePrice;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public int getInOutType() {
        return inOutType;
    }

    public void setInOutType(int inOutType) {
        this.inOutType = inOutType;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getReverseName() {
        return reverseName;
    }

    public void setReverseName(String reverseName) {
        this.reverseName = reverseName;
    }

    public int getPriceType() {
        return priceType;
    }

    public void setPriceType(int priceType) {
        this.priceType = priceType;
    }

    public String getSubjectRefId() {
        return subjectRefId;
    }

    public void setSubjectRefId(String subjectRefId) {
        this.subjectRefId = subjectRefId;
    }

    public int getConsultType() {
        return consultType;
    }

    public void setConsultType(int consultType) {
        this.consultType = consultType;
    }

    @Override
    public String getKey() {
        return id;
    }

    @Override
    public String toString() {
        return name;
    }
    
    public int getLocationRefCount(){
        int locationRefCount=0;
        if(inOutType!=OrderType.STORE_NoChange)
            locationRefCount++;
        if(inOutType1!=OrderType.STORE_NoChange)
            locationRefCount++;
        if(locationRefCount==0&&consultType==CONSULTTYPE_RealStore)
            locationRefCount=1;
        return locationRefCount;
    }

    public boolean isStoreChanged(){
        return inOutType!=OrderType.STORE_NoChange;
    }

    @Override
    public boolean equals(Object obj) {
       if(obj==null)
            return false;
        if(obj instanceof OrderType)
            return ((OrderType)obj).getKey().equals(getKey());
        return getKey().equals(obj);
    }

    public int getFundType() {
        return fundType;
    }

    public void setFundType(int fundType) {
        this.fundType = fundType;
    }

    public String getAttributesetid() {
        return attributesetid;
    }

    public void setAttributesetid(String attributesetid) {
        this.attributesetid = attributesetid;
    }

    public boolean isCashAddAble() {
        return cashAddAble;
    }

    public void setCashAddAble(boolean cashAddAble) {
        this.cashAddAble = cashAddAble;
    }

    public int getOrderLineType() {
        return orderLineType;
    }

    public void setOrderLineType(int orderLineType) {
        this.orderLineType = orderLineType;
    }

     public boolean orderLineAddAble(int oLineType){
        if(orderLineType==OrderType.ORDERLINETYPE_NotSupportAll)
            return false;
        if(orderLineType==OrderType.ORDERLINETYPE_SupportAll)
             return true;
        if(oLineType==OrderLine.CASHLINE&&isCashAddAble()){
              return true;
        }else if(OrderLine.PRODUCTLINE==oLineType){
             if(orderLineType!=OrderType.ORDERLINETYPE_SupportService)
                 return true;
        }else if(OrderLine.SERVICELINE==oLineType){
            if(orderLineType==OrderType.ORDERLINETYPE_SupportService||orderLineType==OrderType.ORDERLINETYPE_SupportUniqueProductAddAndService||orderLineType==OrderType.ORDERLINETYPE_SupportUniqueProductAndService||orderLineType==OrderType.ORDERLINETYPE_SupportProductAndService)
                 return true;
        }
        return false;
    }

    public boolean isConsult() {
        return  consultType!=CONSULTTYPE_Null;
    }

    public String getCategoryid() {
        return categoryid;
    }

    public void setCategoryid(String categoryid) {
        this.categoryid = categoryid;
    }

    public int getInOutType1() {
        return inOutType1;
    }

    public void setInOutType1(int inOutType1) {
        this.inOutType1 = inOutType1;
    }

    public String getStateMachine() {
        return stateMachine;
    }

    public void setStateMachine(String stateMachine) {
        this.stateMachine = stateMachine;
    }

    public boolean isProductConsult() {
        return productConsult;
    }

    public void setProductConsult(boolean productConsult) {
        this.productConsult = productConsult;
    }

    public Date getLastModified() {
        return lastModified;
    }

    public void setLastModified(Date lastModified) {
        this.lastModified = lastModified;
    }

    public void setKey(String key) {
        this.id=key;
    }

    public String getProcessName() {
        return processName;
    }

    public void setProcessName(String processName) {
        this.processName = processName;
    }

    public boolean isServiceCheck() {
        return serviceCheck;
    }

    public void setServiceCheck(boolean serviceCheck) {
        this.serviceCheck = serviceCheck;
    }

	public String getSelectedOrderProcess() {
		return selectedOrderRuleProcess;
	}

	public void setSelectedOrderProcess(String selectedOrderProcess) {
		this.selectedOrderRuleProcess = selectedOrderProcess;
	}

	public int getConsultPriceType() {
		return consultPriceType;
	}

	public void setConsultPriceType(int consultPriceType) {
		this.consultPriceType = consultPriceType;
	}

	public boolean isCheckRule() {
		return checkRule;
	}

	public void setCheckRule(boolean checkRule) {
		this.checkRule = checkRule;
	}  
    
}
